// <span class='date_day_week'></span>
var array_day = new Array("Ahad", "Isnin", "Italia", "Rabu", "Khamis", "Jumaat", "Sabtu");

// <span class='date_month'></span>
var array_month = new Array("Januari", "Februari", "Mac", "April", "Mei", "Jun", "Julai", "Ogos", "September", "Oktober", "November", "Disember"); // <span class='date_year'></span>

// general
var win = ''; // Prize
var win_brand = ''; // Prize
var win_box = 'ixs.webp'; // Prize in box
var title = ''; // Title
var o = '#00a0d6'; // favicon color
var a = "o.webp"; // logo relative path (o.webp)
var a2 = "m_w.webp"; // header right icon relative path (m_w.webp -> white menu) (m_b.webp -> black menu) (s_w.webp -> white cart) (s_b.webp -> black cart)
var b = "Concorso promozionale, valido per oggi - ";
var d = "Caro utente,"; // 
var e = "Ogni Martedi, selezioniamo 7 fortunatio utenti in  <span class = 'date_day_week'></span><span class = 'w'>  </span>, per vincere la carta regaloEurospin"; //
var g = "Devi solo indovinare il pacco esatto!"; //
var h = "<span class='w'>Trova la tua carta regalo</span>"; // 

// social
var j = "Rispondi Mi piace"; // Like
var k = 4281; // page likes
var l = ''; // Reply
var w = ""; // thousand separator for numbers

// modal 1
var m_1_i = 'a.webp'; // Modal 1 image
var m_1_t = 'Concorso Promozionale'; // Modal 1 title
var m_1_d = [{ // Modal 1 description
	"1": "Congratulazioni utente! 🎉",
	"2": "Vogliamo ringraziarti per la tua lealta - quindi ti vogliamo offrire un'esclusiva possibilita' per vincere la<strong> <span class = 'w'>carta regalo Eurospin </span> </strong> solo per oggi!.",
	"3": "Come fare? Trova il pacco corretto! 🎁",
	"4": "<strong> Buona Fortuna!  </strong>",
}];
var m_1_b = 'OK'; // Modal 1 button

// modal 2
var m_2_i = 's.webp'; // Modal 2 image
var m_2_d_2 = ' Hai ancora (2)';
var m_2_d_1 = ' Hai ancora (1)';
var m_2_d = 'Siamo spiacenti, ma questa confezione regalo è vuota.<span id = "try"> </span> tentativi di prova. Buona fortuna'; // Modal 2 description
var m_2_b = 'OK'; // Modal 2 button

// modal 3
var m_3_i = 'ixs.webp'; // Modal 3 image
var m_3_t = 'Complimenti!'; // Modal 3 title
var m_3_s = ' <span class = "w_b"> </span> <span class = "w"> </span> Le tue informazioni sono state conservate'; // Modal 3 title
var m_3_d = [{ // Modal 3 description
	"1": "1. Compilare con cura la consegna e le informazioni di contatto nella pagina successiva.",
	"2": "2. Paga per il tuo regalo.",
	"3": "3. <strong> <span class = 'w'> </span> </strong>Verrai inviato entro 2 giorni lavorativi."
}];
var m_3_b = 'Ottieni un bonus'; // Modal 3 button

// comments
var i = [{
	"1": {
		"name": "Emilia",
		"likes": "",
		"time": "4 minuti fa",
		"comment": {
			"1": "È possibile giocare di nuovo?? :) <span class = 'w_b'> </span> <span class = 'w'> </span> ",
		}
	},
	"2": {
		"name": "Jamie",
		"likes": "",
		"time": "5 minit and",
		"comment": {
			"1": "Ne avevo gia sentito parlare! Il mio carta regalo e' arrivato sta mattina, ma dato che ne ho gia uno credo che questo lo vendero! Grazie a tutti!?",
		}
	},
	"3": {
		"name": "Jessica",
		"likes": "",
		"time": "11 minit and",
		"comment": {
			"1": "Ho vintoooooo!",
		}
	},
	"4": {
		"name": "Mikhail Raja",
		"likes": "",
		"time": "15 minit and",
		"comment": {
			"1": "I won <span class='w'></span>! Wooooooo",
		}
	},
	"5": {
		"name": "Giorgio",
		"likes": "",
		"time": "38 minit and",
		"comment": {
			"1": "Tutto vuoto... :(  ",
		}
	},
	"6": {
		"name": "Enrico",
		"likes": "",
		"time": "42 minit and",
		"comment": {
			"1": "L'ho beccato al secondo tentativo!!! Che figata!!",
		}
	}
}];

// ON PAGE LOAD
$(document).ready(function () {
	$(document).prop('title', title);
	if (a != '') { $('#a .a').append('<img class="left" src="' + a + '" />'); }
	if (a2 != '') { $('#a .a').append('<img class="right" src="' + a2 + '" />'); }
	$('#a .a').append('<div class="z"></div>');
	if (b != '') { $('#b').html('<div class="a">' + b + '</div>'); } else { $('#b').remove(); }
	if (d != '') { $('#d').html(d); } else { $('#d').remove(); }
	if (e != '') { $('#e').html(e); } else { $('#e').remove(); }
	if (g != '') { $('#g').html(g); } else { $('#g').remove(); }
	if (h != '') { $('#h').html(h); } else { $('#h').remove(); }
	if (k != '') { $('#l').html(y(k, w)); } else { $('#l').html(y(1945, w)); }
	if (i != '') {
		var m = '';
		var foo = 0;
		$.each(i, function (idx, obj) {
			$.each(obj, function (idx, obj2) {
				foo++; n = '';
				oc = '';
				if (obj2.comment) {
					$.each(obj2.comment, function (idx, com) {
						oc = oc + "<p>" + com + "</p>";
					});
				}
				if (obj2.likes > 0) { n = y(obj2.likes, w) + ' <span class="m"></span>'; } else { n = '<span class="m"></span>'; }
				m = m + '<div class="j"><div class="n"><img src="'+ + foo + '.webp" /></div><div class="o"><div class="p">' + obj2.name + '</div><div class="q">' + oc + '</div><div class="r">' + l + ' · <span class="k"></span> ' + n + ' · <span class="s">' + obj2.time + '</span></div></div><div class="z"></div></div>';
			});
		});
		$('#k').html(m);
	} else { $('#k').remove(); }
	if (j != '') { $('.m').each(function (i, obj) { $(this).html(j); }); }
	// modal 1
	if (m_1_i != '') { $('#m_1_i').html('<img src="' + m_1_i + '" />'); } else { $('#m_1_i').remove(); }
	if (m_1_t != '') { $('#m_1_t').html(m_1_t); } else { $('#m_1_t').remove(); }
	if (m_1_d != '') {
		var m = '';
		$.each(m_1_d, function (idx, obj) {
			$.each(obj, function (idx, obj2) {
				m = m + '<p>' + obj2 + '</p>';
			});
		});
		$('#m_1_d').html(m);
	} else { $('#m_1_d').remove(); }
	if (m_1_b != '') { $('#m_1_b a').text(m_1_b); } else { $('#m_1_b').text('OK'); }
	// modal 2
	if (m_2_i != '') { $('#m_2_i').html('<img src="' + m_2_i + '" />'); } else { $('#m_2_i').remove(); }
	if (m_2_d != '') { $('#m_2_d').html('<p>' + m_2_d + '</p>'); } else { $('#m_2_d').remove(); }
	if (m_2_b != '') { $('#m_2_b a').text(m_2_b); } else { $('#m_2_b a').text('OK'); }
	// modal 3
	if (m_3_t != '') { $('#m_3_t').html(m_3_t); } else { $('#m_3_t').remove(); }
	if (m_3_s != '') { $('#m_3_s').html(m_3_s); } else { $('#m_3_s').remove(); }
	if (m_3_i != '') { $('#m_3_i').html('<img src="' + m_3_i + '" />'); } else { $('#m_3_i').remove(); }
	if (m_3_d != '') {
		var m = '';
		$.each(m_3_d, function (idx, obj) {
			$.each(obj, function (idx, obj2) {
				m = m + '<p>' + obj2 + '</p>';
			});
		});
		$('#m_3_d').html(m);
	} else { $('#m_3_d').remove(); }
	if (m_3_b != '') { $('#m_3_b a').text(m_3_b); } else { $('#m_3_b a').text('OK'); }

	if (win != '') { $('.w').each(function (i, obj) { $(this).html(win); }); }
	if (win_brand != '') { $('.w_b').each(function (i, obj) { $(this).html(win_brand); }); }

	// load boxes
	for (i = 0; i < 12; i++) {
		$('#i').append('<div class="e" id="b_' + i + '"><div class="f"><div class="g"><a href="#" onclick="cl(\'b_' + i + '\');return false;"><img src="a.webp" /></a></div></div></div>');
	}
	$('#i').append('<div class="z"></div>');

	//load modal 1
	$('#m').fadeIn("slow", function () {
		$('#m_1').fadeIn("200", function () { });
		$('#m_1 .t_a').removeClass('small');
	});

	// dates
	var mydate = new Date();
	mydate.setDate(mydate.getDate() - 0);

	var year = mydate.getYear();
	if (year < 1000) { year += 1900; }

	var day = mydate.getDay();
	var month = mydate.getMonth();

	var daym = mydate.getDate();
	if (daym < 10) { daym = "0" + daym; }

	$('.date_day_number').each(function (i, obj) { $(this).html(daym); });
	$('.date_month').each(function (i, obj) { $(this).html(array_month[month]); });
	$('.date_day_week').each(function (i, obj) { $(this).html(array_day[day]); });

});
// ON CLICK
function cl(x) {
	if (try_num > 2) {
		$('#try').html(m_2_d_2);
	} else {
		$('#try').html(m_2_d_1);
	}
	if (try_num > 1) {
		try_num = try_num - 1;
		$('#' + x).html('<div class="f"><div class="h"><div></div></div></div>');
		$('#m').fadeIn("slow", function () {
			$('#m_2').fadeIn("200", function () { });
			$('#m_2 .t_a').removeClass('small');
		});
	} else {
		// win
		$('#' + x).html('<div class="f"><div class="i"><div></div><div></div><div></div></div></div>');
		if (win_box != '') { $('#' + x + ' .i div:nth-child(1)').css("background", "url('" + win_box + "')"); }
		if (win_box != '') { $('#' + x + ' .i div:nth-child(1)').css("background-size", "contain"); }
		$('#m').fadeIn("slow", function () {
			$('#m_3').fadeIn("200", function () { });
			$('#m_3 .t_a').removeClass('small');
		});
	}
}
// COMMA
function y(x, y) {
	return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, y);
}
function openHref(){
    window.location.href="https://wringital-pation.com/click" ;
}